<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title></title>
    <script src="js/jquery-3.2.1.min.js"></script>
    <script>
        function selectall(){
//            alert("####");
//            var defaultitem = document.getElementsByName('item');
//            var state = document.getElementById('selectAll').checked;
//            for(var i=0; i<defaultitem.length; i++){
//                defaultitem[i].checked=state;
//            }

        var items = $('input[name="item"]');
//        items.prop('checked');
        items.prop('checked',$('#selectAll'));


        }
    </script>
</head>
<body>
    <table>
        <tr>
            <td>
                <input type="checkbox" id="selectAll" onclick="selectall()"/>
            </td>
            <td>姓名</td>
        </tr>
        <tr>
            <td>
                <input type="checkbox" name="item">
            </td>
            <td>张三</td>
        </tr>
        <tr>
            <td>
                <input type="checkbox" name="item">
            </td>
            <td>张三</td>
        </tr>
        <tr>
            <td>
                <input type="checkbox" name="item">
            </td>
            <td>张三</td>
        </tr>

    </table>

</body>
</html>